<template src="./template.html"></template>

<style src="./style.css" scoped></style>
<script>
    import securityBg from "../assets/images/top-bg.png";
    import signSuccessIcon from "../assets/images/signed-icon.png";

    import api from "api/api";
    import modal from "utils/modal";
    import navigator from "utils/navigator";
    import route from "constants/route";
    import constant from "constants/constant";

    const globalEvent = weex.requireModule('globalEvent');

    export default{
        data(){
            return {
                securityBg: securityBg,
                signSuccessIcon: signSuccessIcon,
                pageLoaded: false, //页面加载成功标识
                payWayList: [] //支付方式
            }
        },
        created() {
            let self = this;

            self.getList();

            /**注册监听*/
            globalEvent.addEventListener(constant.EVENT_SECURITY_RELOAD, res=>{
                self.pageLoaded = false;
                self.getList();
            });
        },
        methods: {
             /**
             * @description 获取支付方式列表数据
             */
            getList(){
                let self = this;
                api.sendHttp("getSecurityListApi").then(res=>{
                    self.pageLoaded = true;
                    self.payWayList = res.data || [];
                },res=>{
                    self.pageLoaded = true;
                    modal.toast(res.msg || '加载失败');
                });
            },

             /**
             * @description 支付方式管理跳转
             * @param pw
             * @return {boolean}
             */
            payWayHandler(pw) {
                pw = pw || {};
                if(pw.status === '0') {//未签约
                    if(pw.boundtype === 'sm') {
                        //跳转到扫码免密支付签约页面
                        let options = {
                            url: route.security_pay_open,
                            title: '开通免密支付',
                            navType: -1,
                            params: {
                                signType: pw.signtype
                            }
                        };
                        navigator.push(options);

                    } else if(pw.boundtype === 'card') {
                        //TO-DO 银行卡免密支付，暂未开发
                    }

                } else {//已签约
                    if(pw.boundtype === 'sm') {
                        //跳转到扫码免密支付签约页面
                        let options = {
                            url: route.security_pay_detail,
                            title: pw.title || '免密支付',
                            navType: -1,
                            params: {
                                title: pw.title,
                                signType: pw.signtype
                            }
                        };
                        navigator.push(options);

                    } else if(pw.boundtype === 'card') {
                        //TO-DO 银行卡免密支付，暂未开发
                    }
                }
            }
        },
        destroyed(){
            globalEvent.removeEventListener(constant.EVENT_SECURITY_RELOAD);
        }
    }
</script>
